﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class ManifestLoader 
{
    private static ManifestLoader _Instance;
    public static ManifestLoader Instance
    {
        get
        {
            if (ManifestLoader._Instance == null) ManifestLoader._Instance = new ManifestLoader();
            return ManifestLoader._Instance;
        }
    }
    private AssetBundleManifest manifest;
    /// <summary>
    /// 加载manifest路径
    /// </summary>
    private string manifestPath;
    /// <summary>
    /// 全局AssetBundle
    /// </summary>
    private AssetBundle assetBundle;
    private bool finish;
    public bool finihed { get { return finish; } }
    public ManifestLoader()
    {
        manifestPath = PathUnit.GetWWWPath() + "/" + PathUnit.GetPlatformName();
        manifest = null;
        assetBundle = null;
        finish= false;
    }
    public IEnumerator Load()
    {
        yield return 0;
        //Debug.Log("path > "+ manifestPath);
        assetBundle = AssetBundle.LoadFromFile(manifestPath);
        manifest = assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;
        finish = true;
    }
    /// <summary>
    /// 获取全部依赖关系
    /// </summary>
    /// <param name="bundleName"></param>
    /// <returns></returns>
    public string[] GetAllDependencies(string bundleName)
    {
        return manifest.GetAllDependencies(bundleName);
    }

    public void UnLoad()
    {
        assetBundle.Unload(true);
    }
}
